//##include('../block/lazyload.js');
//##include('../block/doT.js');
//##include('../block/swiper.js');
//##include('../block/initPhotoSwipeIndex.js');


var $doc,$win,pageSize= 1,_threshold=0,$cluelist;

var _view = {

    init: function() {
        this.lazyimg();
        this.loadList();
    },
    loadList : function(){
        var _this = this;
        var urls = window.location.href;
        var url_params = urls.substring(parseInt(urls.lastIndexOf('/')+1));
        var id = url_params.split('_')[1];
        $.ajax({

            type: 'GET',
            url: '/hot/hot_apis/hotlist?id='+ id +'&p='+pageSize,
            dataType: 'json',
            success: function(data){

                var len = data.list.length;

                if(len > 0){

                    _this.loadlingActive();

                    var temID = $cluelist.attr('temId');
                    var tmpl = $("#"+temID).html();
                    var doTtmpl = doT.template(tmpl);

                    $cluelist.append(doTtmpl(data));
                    len < 10 ? _this.noDataActive() : _this.initLoadActive();

                    pageSize++;
                    _this.lazyimg();
                    //_this.initReadedStyle($cluelist.find('.item'));
                }else{
                    _this.noDataActive();
                }
            },
            error: function(){
                console.log('Ajax error!');
            }
        });
    },
    initLoadActive : function(){
        $dropDownWrapper.find('.msg').removeClass('active');
        $dropDownMsg.addClass('active');
    },

    loadlingActive : function(){
        $dropDownWrapper.find('.msg').removeClass('active');
        $dataLoading.addClass('active');
    },

    noDataActive : function(){
        $dropDownWrapper.find('.msg').removeClass('active');
        $noData.addClass('active');
    },
    lazyimg:function(){
        $(".lazy").lazyload({
            effect : "show",
            failurelimit : 10,
            threshold : 200
        });
    }
};

var _event = {

    bind: function() {
        $win.on('scroll',this.scrollLoad);

    },
    scrollLoad : function(){
        var currScrollT = $win.scrollTop();
        //console.log(currScrollT);

        // 滚动页面触发加载数据
        if(($doc.height() - _threshold) <= (document.documentElement.clientHeight + currScrollT)){
            _view.loadList();
        }
    }
};

var _data = {};

function init() {

    _view.init();
    _event.bind();

}

$(document).ready(function() {

    $doc = $(document);
    $win = $(window);
    $cluelist = $('#clue-list');
    $mainContainer = $('#main-container');
    $dropDownWrapper = $('.drop-down-wrapper');
    $dropDownMsg = $('.drop-down-msg');
    $dataLoading = $('.data-loading');
    $noData = $('.no-data');
    init();
});